﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition;
using System.Reflection;

namespace SoundEdge.Common
{
    public static class MEFUtils
    {
        private static List<CompositionContainer> _assemblyContainers = new List<CompositionContainer>();

        public static CompositionContainer GetAssemblyContainer()
        {
            CompositionContainer container = _assemblyContainers.FirstOrDefault(item => ((AssemblyCatalog)item.Catalog).Assembly.FullName == Assembly.GetCallingAssembly().FullName);
            if (container == null)
            {
                AssemblyCatalog catalog = new AssemblyCatalog(Assembly.GetCallingAssembly());
                container = new CompositionContainer(catalog);
                //container.ComposeParts(
                _assemblyContainers.Add(container);
            }
            return container;
        }
    }
}
